

package com.kimo.shop.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kimo.shop.bean.model.OrderInvoice;
import com.kimo.shop.dao.OrderInvoiceMapper;
import com.kimo.shop.service.OrderInvoiceService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 *
 *
 * @author kimo-taozhouchuan
 * @date 2021-08-16 14:22:47
 */
@Service
@AllArgsConstructor
public class OrderInvoiceServiceImpl extends ServiceImpl<OrderInvoiceMapper, OrderInvoice> implements OrderInvoiceService {

    private final OrderInvoiceMapper orderInvoiceMapper;

    @Override
    public IPage<OrderInvoice> page(Page page, OrderInvoice orderInvoice) {
        return orderInvoiceMapper.getShopPage(page,orderInvoice);
    }

    @Override
    public IPage<OrderInvoice> pageUserInvoice(Page page, String userId) {
        return orderInvoiceMapper.getUserInvoicePage(page,userId);
    }

    @Override
    public OrderInvoice getById(Long orderInvoiceId) {
        return orderInvoiceMapper.getById(orderInvoiceId);
    }

    @Override
    public Long getByOrderNumber(String orderNumber) {
        return  orderInvoiceMapper.getByOrderNumber(orderNumber);
    }

    @Override
    public boolean isUpload(String orderId) {
        return orderInvoiceMapper.isUpload(orderId) >= 1;
    }

    @Override
    public void deleteBatch(List<String> orderNumbers) {
        ArrayList<String> orderDeleteIds = new ArrayList<>();
        for (String orderNumber : orderNumbers) {
            if (Objects.nonNull(orderInvoiceMapper.getByOrderNumber(orderNumber))){
                //如果该订单有发票信息
                orderDeleteIds.add(orderNumber);
            }
        }
        if (CollectionUtil.isNotEmpty(orderDeleteIds)){
            orderInvoiceMapper.deleteBatch(orderDeleteIds);
        }
    }
}
